#!/usr/bin/python3

try:
    n = int(input())
    r = input()
    a = [0, 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97, 113, 131, 197, 199, 311, 337, 373, 719, 733, 919, 971, 991,
         1193, 1931, 3119, 3779, 7793, 7937, 9311, 9377, 11939, 19391, 19937, 37199, 39119, 71993, 91193, 93719, 93911,
         99371, 193939, 199933, 319993, 331999, 391939, 393919, 919393, 933199, 939193, 939391, 993319, 999331]
    flag = 0
    for i in range(55, 0, -1):
        if str(a[i]) in r:
            print(a[i])
            flag = 1
            break
    if flag == 0:
        print('-1')

except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
